﻿using System;
using UnityEngine;
using Object = UnityEngine.Object;

public class Debuger
{
    public enum Level
    {
        LOG,
        WARNING,
        ERROR,
        EXCEPTION,
        DISABLE
    }

    public static Level LogLevel;

    public static void DrawLine(Vector3 start, Vector3 end)
    {
        DrawLine(start, end, Color.white, 0f, false);
    }

    public static void DrawLine(Vector3 start, Vector3 end, Color color)
    {
        DrawLine(start, end, color, 0f, false);
    }

    public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration)
    {
        DrawLine(start, end, color, duration, false);
    }

    public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration, bool depthTest)
    {
        Debug.DrawLine(start, end, color, duration, depthTest);
    }

    public static void DrawRay(Vector3 start, Vector3 dir)
    {
        DrawRay(start, dir, Color.white, 0f, false);
    }

    public static void DrawRay(Vector3 start, Vector3 dir, Color color)
    {
        DrawRay(start, dir, color, 0f, false);
    }

    public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration)
    {
        DrawRay(start, dir, color, duration, false);
    }

    public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration, bool depthTest)
    {
        Debug.DrawRay(start, dir, color, duration, depthTest);
    }

    [System.Diagnostics.Conditional("LOG")]
    public static void Log(string format, params object[] args)
    {
        if (LogLevel <= Level.LOG)
        {
            Log(string.Format(format, args) as object, null);
        }
    }

    [System.Diagnostics.Conditional("LOG")]
    public static void Log(object message)
    {
        Log(message, null);
    }
    
    public static void Log(object message, Object context)
    {
        if (LogLevel <= Level.LOG)
        {
            Debug.Log(string.Format("[{0}] {1}", LogDateTime(), message), context);
        }
    }

    [System.Diagnostics.Conditional("LOG")]
    public static void LogWarning(string format, params object[] args)
    {
        if (LogLevel <= Level.WARNING)
        {
            LogWarning(string.Format(format, args) as object,null);
        }
    }

    [System.Diagnostics.Conditional("LOG")]
    public static void LogWarning(object message)
    {
        LogWarning(message, null);
    }
    
    public static void LogWarning(object message, Object context)
    {
        if (LogLevel <= Level.WARNING)
        {
            Debug.LogWarning(string.Format("[{0}] {1}", LogDateTime(), message), context);
        }
    }

    [System.Diagnostics.Conditional("LOG")]
    public static void LogError(string format, params object[] args)
    {
        if (LogLevel <= Level.ERROR)
        {
            LogError(string.Format(format, args) as object, null);
        }
    }

    [System.Diagnostics.Conditional("LOG")]
    public static void LogError(object message)
    {
        LogError(message, null);
    }

    public static void LogError(object message, Object context)
    {
        if (LogLevel <= Level.ERROR)
        {
            Debug.LogError(string.Format("[{0}] {1}", LogDateTime(), message), context);
        }
    }

    [System.Diagnostics.Conditional("LOG")]
    public static void LogException(Exception exception)
    {
        LogException(exception, null);
    }
    
    public static void LogException(Exception exception, Object context)
    {
        if (LogLevel <= Level.EXCEPTION)
        {
            Debug.LogException(exception, context);
        }
    }

    private static string LogDateTime()
    {
        return GetNowDateTime();
    }

    private static string GetNowDateTime(string format = "HH:mm:ss.fff")
    {
        return DateTime.Now.ToString(format);
    }
}
